<?php
    require_once "Repository/IRepository.php";
    
    class GebruikerRepository implements IRepository 
    {
        private $client;

        public function __construct($client)
        {
            $this->client = $client;
        }
        
        public function Create()
        {
            
        }
        
        public function Read()
        {
            
        }
        
        public function Update($id)
        {
        
        }
        
        public function Delete($id)
        {
            
        }
        
        public function Bestaat($naam, $wachtwoord)
        {
            $link = $this->client->connect();
            $query = "SELECT * FROM gebruiker WHERE inlognaam = '" . $naam . "' AND wachtwoord = '" . $wachtwoord . "';";
            $result = mysql_query($query);
            $id = -1;
            if($result !== false)
            {
                $row = mysql_fetch_array($result);
                if(isset($row['id']))
                {
                    $id =  $row['id'];
                }
            }
            else
            {
                echo mysql_error();
            }
            $this->client->close();
            return $id;
        }
        
        public function GetRolId($userId)
        {
            $link = $this->client->connect();
            $query = "SELECT * FROM gebruiker WHERE id = '" . $userId . "';";
            $result = mysql_query($query);
            $rol = -1;
            if($result !== false)
            {
                $row = mysql_fetch_array($result);
                if(isset($row['rol_id']))
                {
                    $rol =  $row['rol_id'];
                }
            }
            else
            {
                echo mysql_error();
            }
            $this->client->close();
            return $rol;
        }
   }
?>